# Maintainer: Biswapriyo Nath <nathbappai@gmail.com>

_realname=scour
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
_realver=038.1
pkgver=0.38.1
pkgrel=1
pkgdesc="An SVG scrubber (mingw-w64)"
arch=('any')
url="https://github.com/scour-project/scour"
license=('Apache')
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-python-setuptools"
         "${MINGW_PACKAGE_PREFIX}-python-six")
source=("${_realname}-${pkgver}.tar.gz"::"https://github.com/scour-project/scour/archive/v${_realver}.tar.gz")
sha256sums=('0d2f88170305d54b143410276ff84da98e3ae9c36abe52430d9c2b510fa77884')

prepare() {
  cd "${srcdir}"
  mv ${_realname}-${_realver} ${_realname}-${pkgver}
  cp -r ${_realname}-${pkgver} python-build-${CARCH}
}

build() {
  cd "${srcdir}/python-build-${CARCH}"
  ${MINGW_PREFIX}/bin/python setup.py build
}

check() {
  cd "${srcdir}/python-build-${CARCH}"
  ${MINGW_PREFIX}/bin/python setup.py check
}

package() {
  cd "${srcdir}/python-build-${CARCH}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX} \
        --root "${pkgdir}" --optimize=1 --skip-build

  install -Dm644 "${srcdir}/${_realname}-${pkgver}/LICENSE" "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"

  local PREFIX_WIN=$(cygpath -wm ${MINGW_PREFIX})
  # fix python command in files
  for _f in "${pkgdir}${MINGW_PREFIX}"/bin/*.py; do
    sed -e "s|/usr/bin/env |${MINGW_PREFIX}|g" \
        -e "s|${PREFIX_WIN}|${MINGW_PREFIX}|g" -i ${_f}
  done
}
